package com.lh.java.connect;



import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;


/**
 ************************************************
 ** Module : mysql原始的数据库连结
 ** Date: 2013-4-3  Time: 下午05:42:32 
 ** Author lh 
 ************************************************ 
 */
public class MysqlConnetOriginal {

	/**
	 * 功能描述  
	 * @throws SQLException 
	 * @Author: lh  2013-4-3 下午05:42:29
	 */
	public static void main(String[] args) throws SQLException {
		String userName = "root";
		String password = "123456";
		String url = "jdbc:mysql://192.168.1.8:3306/ad_ceshi";
		try {
			try {
				Class.forName("com.mysql.jdbc.Driver").newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();			
		}
		Connection con = null;
		try {
			con = (Connection) DriverManager.getConnection(url, userName, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		Statement  statement=null;
		try {
			statement = (Statement) con.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		String sql="SELECT * FROM users limit 5";
		ResultSet rs = null;
		try {
			rs = statement.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		while(rs.next()){
			long  id = rs.getLong(1);
			String pa = rs.getNString(2);
			String email = rs.getString("email");
			System.out.println("id="+id+" password="+pa+" email="+email);
		}

	}

}
